package com.xqb.modules.controller.chat;

import com.alibaba.fastjson.JSONObject;
import com.xqb.common.core.controller.BaseController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.xqb.server.WebSocketServer.sessionMap;


@RestController
@RequestMapping("/list")
public class UserListController extends BaseController {

    /**
     * 判断用户名是否存在与于聊天室
     *
     * @param userId 用户id
     * @return json
     */
    @GetMapping("/{userId}")
    public JSONObject getUsername(@PathVariable("userId") String userId) {
        JSONObject jsonObject = new JSONObject();
        boolean isEmpty = sessionMap.isEmpty();
        boolean isExist = sessionMap.containsKey(userId);
        jsonObject.put("isEmpty", isEmpty);
        jsonObject.put("isExist", isExist);
        return jsonObject;
    }


}
